package com.edu.controller;

import com.edu.entity.Menu;
import com.edu.entity.Role;
import com.edu.entity.User;
import com.edu.service.MenuService;
import com.edu.utils.CommonUtils;
import com.edu.utils.FileUploader;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@Controller
@RequestMapping("/Test")
public class UnitTestController extends BaseController {
    public String DIR = "D:\\java1\\upload\\user\\";
    @RequestMapping("/showImage")
    public void showImage(HttpServletResponse resp){
        try {
            outFile(resp, DIR, "stu01.png");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @RequestMapping(
            value = "/upload",
            produces = "text/html;charset=UTF-8"
    )
    @ResponseBody
    public String upload(
            @RequestParam("pdfFile") MultipartFile pdfFile,
            @RequestParam("note")String note ){
        //1.创建文件容器
        FileUploader UPD = new FileUploader(pdfFile,DIR,true);
        try {
            UPD.writeFile();
        }catch (Exception e){
            e.printStackTrace();
            return "上传文件失败.";
        }

        return "上传文件成功.";
    }
}
